package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MainActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.forget.ForgetPasswordActivity;
import com.wnhz.work.yz.activity.register.RegisterActivity;

/**
 * ---登录首页
 */
public class LoginFirstActivity extends BaseActivity implements View.OnClickListener {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_first);
        initView();
    }

    private void initView() {

        findViewById(R.id.tv_login).setOnClickListener(this);
        findViewById(R.id.tv_register).setOnClickListener(this);
        findViewById(R.id.tv_agreement).setOnClickListener(this);
        findViewById(R.id.tv_forget).setOnClickListener(this);
        findViewById(R.id.rl_close).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.rl_close:
                onBackPressed();
//                finish();
                break;

            //登录
            case R.id.tv_login:
                intent = new Intent(this, LoginNewActivity.class);
                startActivity(intent);
                break;

            //注册
            case R.id.tv_register:
                intent = new Intent(this, RegisterActivity.class);
                startActivity(intent);
                break;

            //协议
            case R.id.tv_agreement:
                intent = new Intent(this, AgreementActivity.class);
                startActivity(intent);
                break;

            //忘记密码
            case R.id.tv_forget:
                intent = new Intent(this, ForgetPasswordActivity.class);
                startActivity(intent);
                break;

            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        SharedPreferences sp = getSharedPreferences("login", 0);
        sp.edit().clear().commit();
        MyApplication.getInstance().userBean = null;
        Intent intent = new Intent(LoginFirstActivity.this, MainActivity.class);
        intent.putExtra("Pagination", 0);
        startActivity(intent);
        finish();
    }
}
